package com.ymm.system.dao.mapper;

import com.ymm.system.api.constants.CargoEntity;
import com.ymm.system.api.constants.LltorderEntity;
import com.ymm.system.api.dto.*;
import com.ymm.system.api.dto.ShipperOrderBriefResponse;
import com.ymm.system.api.dto.ShipperOrderDetailResponse;
import com.ymm.system.api.utils.Result;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;

/**
 * 
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2022-08-03
 */
@Mapper
public interface LltorderMapper{

    /**
     * 查询所有订单详情
     *
     * @return
     */
    List<LltorderDetailsDTO> listLltorderDetails();

    @Cacheable(value = "orderDetails", key = "#orderId")
    LltorderEntity getOrderDetailsByOrderId(@Param("orderId") Long orderId);

    /**
     * 插入一条新订单数据
     *
     * @param
     * @return
     */
    void insertNewOrder(@Param("lltorderEntity") LltorderEntity lltorderEntity);


    List<OrderShowDTO> getAllOrderDetails();

    BigInteger getDriverId(Long orderId);

    Long getShipperId(Long orderId);

    List<Long> getAllShipperId();

    List<BigInteger> getAllDriverId();

    @Cacheable(value = "shipperOrderDetail", key = "#orderId")
    ShipperOrderDetailResponse getShipperOrderDetailByOrderId(Long orderId);

//    根据司机Id查找进行中的订单的创建时间
     List<Date> getOnShelfOrderDate(Long driverId);

    List<ShipperOrderDetailResponse> getShipperOrderDetailByReceiverPhone(String cargoReceiverPhone);

    /**
     * 8月7日guorui +
     * 更新订单状态
     * @param orderId
     * @param orderShipperState
     */
    @CacheEvict(value = {"orderDetails", "shipperOrderDetail"}, key = "#orderId")
    void updateOrderShipperStateByOrderId(@Param("orderId") Long orderId, @Param("orderShipperState") Integer orderShipperState);

    /**
     * 8月7日guorui +
     * 根据货主id和订单状态获取给货主看的简要订单列表
     * @param shipperId
     * @param orderShipperState
     * @return
     */
    List<ShipperOrderBriefResponse> listShipperOrderBriefsByShipperIdAndOrderShipperState(@Param("shipperId") Long shipperId, @Param("orderShipperState") Integer orderShipperState);

    OrderAndCargoInfoResponse getOrderAndCargoInfoByOrderId(Long orderId);

    /**
     * 根据运单Id获取订单Id、货主Id、货源Id和司机Id
     * @param tradeId 运单Id
     * @return IdInfoDTO
     */
    IdInfoDTO getIdInfoDTOByTradeId(Long tradeId);

    /**
     * 更新取消状态（目前更新后必为取消订单的某种情况）
     * @param orderId
     */
    @CacheEvict(value = {"orderDetails", "shipperOrderDetail"}, key = "#orderId")
    void updateOrderCancelType(@Param("orderId") Long orderId, @Param("orderCancelType") Integer orderCancelType);

    /**
     * 更新取消原因
     * @param orderId
     * @param orderCancelReason
     * @param orderCancelDescription
     */
    @CacheEvict(value = {"orderDetails", "shipperOrderDetail"}, key = "#orderId")
    void updateOrderCancelReason(@Param("orderId") Long orderId, @Param("orderCancelReason") Integer orderCancelReason,
                                 @Param("orderCancelDescription") String orderCancelDescription);

    /**
     * 获取所有已卸货超过三天的订单
     */
    List<Long> listDischargedOutTimeOrderId();
}